package com.ny.demo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Test {
    public static void main(String[] args) throws IOException {
        //将数据输入到文件中FileOutputStream
        String date="劳动节快乐";
        FileOutputStream outputStream=new FileOutputStream("1.txt");
        //字符转换成字节
        byte[] bytes=date.getBytes();
        outputStream.write(bytes);

        //从文件获取数据,输出到控制台FileOutputString
        FileInputStream inputStream =new FileInputStream("1.txt");
        //创建一个字节数组
        byte[] buffer=new byte[1024];
        StringBuilder conten=new StringBuilder();
        int length;
        while((length = inputStream.read(buffer))!=-1){
            conten.append(new String(buffer,0,length, StandardCharsets.UTF_8));
        }
        System.out.println(conten.toString());



    }
}
